package ynu.edu.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import ynu.edu.po.Orders;
import ynu.edu.service.OrdersService;


import java.util.List;

@RestController
@RequestMapping("/OrdersController")
public class OrdersController {

    @Autowired
    private OrdersService ordersService;

    @RequestMapping("/createOrders")
    public int createOrders(Orders orders){

        return ordersService.createOrders(orders.getUserId(),orders.getBusinessId(), orders.getDaId(), orders.getOrderTotal());
    }

    @RequestMapping("/getOrdersById")
    public Orders getOrdersById(Orders orders){
        return ordersService.getOrdersById(orders.getOrderId());
    }

    @RequestMapping("/listOrdersByUserId")
    public List<Orders> listOrdersByUserId(Orders orders){
        return ordersService.listOrdersByUserId(orders.getUserId());
    }

    @RequestMapping("/updateState")
    public int updateState(Orders orders) {
        return ordersService.updateOrdersState(orders.getOrderId(), orders.getOrderState());
    }

}
